package com.rapid.maintenance.adapter;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.BaseViewHolder;
import com.rapid.maintenance.R;
import com.rapid.maintenance.base.BaseAdapter;

/**
 *
 */
public class MachiningTagAdapter extends BaseAdapter<String> {

    private String selected;

    public MachiningTagAdapter() {
        super(R.layout.item_tag);
        setOnItemClickListener((adapter, view, position) -> {
            int old = -1;
            if (selected != null) {
                old = getData().indexOf(selected);
            }
            selected = getItem(position);
            if (old != -1) notifyItemChanged(old);
            notifyItemChanged(position);
        });
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, String item) {
        helper.setText(R.id.tag, item);
        helper.itemView.setSelected(item.equals(selected));
    }
}
